<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="content-type">
  <title>HelloUniverse</title>
</head>
<body>
<h2>HelloUniverse: A Sample Java
3D Program</h2>
<p>Here are code fragments from a simple program, <code>HelloUniverse.java</code>,
that creates a cube and a RotationInterpolator behavior object that
rotates the cube at a constant rate of pi/2 radians per second. The
HelloUniverse class creates the branch graph
that includes the cube and the RotationInterpolator behavior. It then
adds this branch graph to the Locale object generated by the
SimpleUniverse utility.
</p>
<pre><hr><br>public class HelloUniverse ... {<br>    public BranchGroup createSceneGraph() {<br><i>        // Create the root of the branch graph<br></i>        BranchGroup objRoot = new BranchGroup();<br><br><i>        // Create the TransformGroup node and initialize it to the<br>        // identity. Enable the TRANSFORM_WRITE capability so that<br>        // our behavior code can modify it at run time. Add it to<br>        // the root of the subgraph.<br></i>        TransformGroup objTrans = new TransformGroup();<br>        objTrans.setCapability(<br>                TransformGroup.ALLOW_TRANSFORM_WRITE);<br>        objRoot.addChild(objTrans);<br><br><i>        // Create a simple Shape3D node; add it to the scene graph.<br></i>        objTrans.addChild(new ColorCube(0.4));<br><br><i>        // Create a new Behavior object that will perform the<br>        // desired operation on the specified transform and add<br>        // it into the scene graph.<br></i>        Transform3D yAxis = new Transform3D();<br>        Alpha rotationAlpha = new Alpha(-1, 4000);<br>        RotationInterpolator rotator = new RotationInterpolator(<br>                rotationAlpha, objTrans, yAxis,<br>                0.0f, (float) Math.PI*2.0f);<br>        BoundingSphere bounds =<br>            new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);<br>        rotator.setSchedulingBounds(bounds);<br>        objRoot.addChild(rotator);<br><br><i>        // Have Java 3D perform optimizations on this scene graph.</i><br>        objRoot.compile();<br><br>        return objRoot;<br>    }<br><br>    public HelloUniverse() {<br><i>        &lt;set layout of container, construct canvas3d, add canvas3d&gt;<br><br>        // Create the scene; attach it to the virtual universe<br></i>        BranchGroup scene = createSceneGraph();<br>        SimpleUniverse u = new SimpleUniverse(canvas3d);<br>        u.getViewingPlatform().setNominalViewingTransform();<br>        u.addBranchGraph(scene);<br>    }<br>}</pre>
</body>
</html>
